<?php
if($_SESSION['sid']!=1 && $_SESSION['sid']!=94) exit('请登录<a href="http://dev.12301.cc/">首页</a>');
/**
 * Created by PhpStorm.
 * User: Guangpeng Chen
 * Date: 15-8-12
 * Time: 下午4:00
 */
require_once("/var/www/html/new/conf/le.je");
$le=new go_sql();
$le->connect();
include '../../common/page.php';
$currentPage =$_GET["currentPage"]?$_GET["currentPage"]:1;
$page= $_GET['partner']=='lvmama'?50:10;
$pageSize    =$_GET["pageSize"]?$_GET["pageSize"]:$page;
//$offset      =($currentPage-1)*$pageSize;
if ($_GET['partner']=='ctrip') {
    include 'Ctrip.php';
    if($_GET['c_id']!=''){
        $ctrip = new Api\Ctrip();
        $Get_lID = $ctrip->TicketSenicSpotInfo_simple($_GET['c_id']+0);
        goto jump;
    }
    $ctrip =  new Api\Ctrip();
    $zone = $_GET['zone'];
    $Get_lID = $ctrip->TicketSenicSpotSearch($zone, $currentPage, $pageSize); //print_r($Get_lID);
    $total = $Get_lID['count'];
}else if ($_GET['partner']=='lvmama'){
    include 'Lvmama.php';
    if($_GET['c_id']!=''){
        $ctrip = new Api\LvMaMa();
        $Get_lID = $ctrip->productInfoList($_GET['c_id']+0);
        goto jump;
    }
    $ctrip = new Api\LvMaMa();
    $Get_lID = $ctrip->productInfoListByPage($currentPage);
    $total = 4240;
}else if ($_GET['partner']=='qunar'){
    include '/var/www/html/new/d/module/wxh/api_import/qunar2B_demo.php';
    if($_GET['c_id']!=''){
        $ctrip = new Qunar2B();
        $Get_lID = $ctrip->singleProduct($_GET['c_id']+0);
        goto jump;
    }
    $ctrip = new Qunar2B();
    $Get_lID = $ctrip->productInfoList($currentPage);
    $total = $Get_lID['totalCount'];
}
jump:
if($_GET['partner']=='ctrip') {
    $apply_did=4274;
}else if($_GET['partner']=='lvmama') {
    $apply_did=50618;
}else if($_GET['partner']=='qunar') {
    $apply_did=49495;
    $html=<<<HTML
 <td>供应商账号:<input name="aid" class="aid-input" type="text" placeholder="例如:124683"  value="{$_GET['account']}"></td>
HTML;

}
if(count($Get_lID['list'])) {
    foreach ($Get_lID['list'] as $list) {
        $sql = "select id from uu_land where apply_did=$apply_did and title='{$list['Name']}' limit 1";
        $GLOBALS['le']->query($sql);
        $GLOBALS['le']->fetch_assoc();
        $lid = $GLOBALS['le']->f('id');
        $daoru = $lid?$html.'<td>lid:'.$lid.' <input type="button" value="重新导入" class="import_zax" ></td>':
            $html.'<td><input type="button" value="导入" class="import_zax" ></td>';
        $html_list .= <<<HTML
        <tr>
            <td class="id_post"><input name="id[]" type="checkbox" value="{$list['id']}" /></td>
            <td>{$list['id']}</td>
            <td><a target="_blank" href="detail.php?channel=ctrip&id={$list['id']}">{$list['Name']}</a></td>
            $daoru
        </tr>
HTML;
    }
}
?>
<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>第三方平台产品导入</title>
    <!--    <link rel="stylesheet" href="//www.16u.com/jq/css/aliceui.min.css"/>-->
    <link media="all" href="https://a.alipayobjects.com/alice/one/1.2.2/one.css" rel="stylesheet">
    <link rel="stylesheet" href="http://dev.12301.cc/css/page.css"/>
    <style type="text/css">
        #wrapper{width:1280px; margin:20px auto;}
    </style>
    <script language="javascript" src="http://dev.12301.cc/js/jquery-1.8.0.min.js"></script>
</head>
<body>
<body>
<div id="wrapper">
    <div id="search" class="ui-box">
        <div class="ui-box-head">
            <h3 class="ui-box-head-title">查询条件</h3>
            <span class="ui-box-head-text"></span>
            <a href="#" class="ui-box-head-more"></a>
        </div>
        <div class="ui-box-container">
            <div class="ui-box-content">
                <form action="" class="ui-form">
                    <select name="partner" class="sel">
                        <option  <?=$_GET['partner']=="ctrip"?"selected":""?> value="ctrip"> 携程网</option>
                        <option  <?=$_GET['partner']=="lvmama"?"selected":""?> value="lvmama">驴妈妈</option>
                        <option  <?=$_GET['partner']=="qunar"?"selected":""?> value="qunar">去哪儿</option>

                    </select>
                    <label>
                        <span class="zone-input" style="display: inline" >
                        <?php if($_GET['partner']=='ctrip' || empty($_GET['partner'])){
                            echo " 地区:  <input name='zone' class='zone-input' type='text' placeholder='例如:莆田' value='{$_GET['zone']}'>";
                        }?>
                        </span>
                        产品ID:<input name="c_id" class="ui-input" type="text" placeholder="例如:4140"  value="<?=$_GET['c_id']?>">
                        <!--                        <span class="aid-input" style="display: none" >-->
                        <!--                        供应商账号:<input name="aid" class="uid-input" type="text" placeholder="例如:124683"  value="--><?//=$_GET['account']?><!--">-->
                        <!--                        </span>-->
                    </label>
                    <button type="submit" class="ui-button ui-button-mblue">查找</button>
                    <input type="hidden" value="0" id="search_mark">
                    <li id="setimg" style="display: none"><img src="http://dev.12301.cc/web/rebuild/yyl/ordersearchpage/images/load.gif" /></li>
                </form>
            </div>
        </div>
    </div>
    <table cellspacing="0" class="ui-table">
        <thead>
        <tr>
            <th style="width: 30px;">选择</th>
            <th>ID</th>
            <th>产品名</th>
            <?=$_GET['partner']=='qunar'?'<th>供应商账号</th>':''?>
            <th>操作</th>
        </tr>
        </thead>
        <tbody>
        <?=$html_list;?>
        </tbody>
        <tfoot>
        <td colspan="4"><?page($total, $currentPage, $pageSize);?></td>
        </tfoot>
    </table>
</div>
</body>
<script>
    $(function(){
        $('.sel').change(function(){
            if($('.sel').val()=='ctrip'){
                $('.zone-input').show()
            }else{
                $('.zone-input').hide()
            }
        })
        $('table').on('click','td input.import_zax',function(){

            var partner=$("select[name='partner']").find('option:selected').val()
//        var flag   =$(".aid-input").val();
            var flag = $(this).parent().prev().children('.aid-input').val()
            if(partner=='qunar' ){
                if(!flag) {
                    alert('请输入供应商账号');
                    return;
                }
            }
            var c_id = $(this).parent().siblings('.id_post').children().val();
            var data = {
                action  : 'import',
                c_id    : c_id,
                partner : partner,
                flag    : flag
            };
            var target = $(this);
            $.ajax({
                url:'http://dev.12301.cc/module/api_import/ajax_zax.php',
                data:data,
                dataType:"json",
                type: 'POST',
                "success":function(data){
                    if(data.code==200){
                        alert('导入成功');
                        target.parent().html('lid:'+data.lid);
                    }
                    else  alert('导入失败');
                },
                complete:function(){
                }
            })
        })
    })
</script>
</html>